home *** CD-ROM | disk | FTP | other *** search
/ Digitalfoto 118 / Digitalfoto 118.iso / mac / programas / 00 / start.swf / scripts / __Packages / mx / video / SMILManager.as < prev    next >
Text File  |  2009-11-16  |  10KB  |  292 lines

  1. class mx.video.SMILManager
  2. {
  3.    static var version = "1.0.1.10";
  4.    static var shortVersion = "1.0.1";
  5.    static var ELEMENT_NODE = 1;
  6.    function SMILManager(owner)
  7.    {
  8.       this._owner = owner;
  9.    }
  10.    function connectXML(url)
  11.    {
  12.       this._url = this.fixURL(url);
  13.       this.xml = new XML();
  14.       this.xml.onLoad = mx.utils.Delegate.create(this,this.xmlOnLoad);
  15.       this.xml.load(this._url);
  16.       return false;
  17.    }
  18.    function fixURL(origURL)
  19.    {
  20.       if(origURL.substr(0,5).toLowerCase() == "http:" || origURL.substr(0,6).toLowerCase() == "https:")
  21.       {
  22.          var _loc2_ = origURL.indexOf("?") < 0 ? "?" : "&";
  23.          return origURL + _loc2_ + "FLVPlaybackVersion=" + mx.video.SMILManager.shortVersion;
  24.       }
  25.       return origURL;
  26.    }
  27.    function xmlOnLoad(success)
  28.    {
  29.       try
  30.       {
  31.          if(!success)
  32.          {
  33.             this._owner.helperDone(this,false);
  34.          }
  35.          else
  36.          {
  37.             this.baseURLAttr = new Array();
  38.             this.videoTags = new Array();
  39.             var _loc2_ = this.xml.firstChild;
  40.             var _loc6_ = false;
  41.             while(_loc2_ != null)
  42.             {
  43.                if(_loc2_.nodeType == mx.video.SMILManager.ELEMENT_NODE)
  44.                {
  45.                   _loc6_ = true;
  46.                   if(_loc2_.nodeName.toLowerCase() == "smil")
  47.                   {
  48.                      break;
  49.                   }
  50.                }
  51.                _loc2_ = _loc2_.nextSibling;
  52.             }
  53.             if(!_loc6_)
  54.             {
  55.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" No root node found; if url is for an flv it must have .flv extension and take no parameters");
  56.             }
  57.             else if(_loc2_ == null)
  58.             {
  59.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Root node not smil");
  60.             }
  61.             else
  62.             {
  63.                var _loc5_ = false;
  64.                var _loc4_ = 0;
  65.                for(; _loc4_ < _loc2_.childNodes.length; _loc4_ = _loc4_ + 1)
  66.                {
  67.                   var _loc3_ = _loc2_.childNodes[_loc4_];
  68.                   if(_loc3_.nodeType != mx.video.SMILManager.ELEMENT_NODE)
  69.                   {
  70.                      continue;
  71.                   }
  72.                   if(_loc3_.nodeName.toLowerCase() == "head")
  73.                   {
  74.                      this.parseHead(_loc3_);
  75.                      continue;
  76.                   }
  77.                   if(_loc3_.nodeName.toLowerCase() == "body")
  78.                   {
  79.                      _loc5_ = true;
  80.                      this.parseBody(_loc3_);
  81.                      continue;
  82.                   }
  83.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag " + _loc3_.nodeName + " not supported in " + _loc2_.nodeName + " tag.");
  84.                }
  85.                if(!_loc5_)
  86.                {
  87.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag body is required.");
  88.                }
  89.                else
  90.                {
  91.                   this._owner.helperDone(this,true);
  92.                }
  93.             }
  94.          }
  95.       }
  96.       catch(err:Error)
  97.       {
  98.          this._owner.helperDone(this,false);
  99.          throw err;
  100.       }
  101.    }
  102.    function parseHead(parentNode)
  103.    {
  104.       var _loc4_ = false;
  105.       var _loc3_ = 0;
  106.       while(_loc3_ < parentNode.childNodes.length)
  107.       {
  108.          var _loc2_ = parentNode.childNodes[_loc3_];
  109.          if(_loc2_.nodeType == mx.video.SMILManager.ELEMENT_NODE)
  110.          {
  111.             if(_loc2_.nodeName.toLowerCase() == "meta")
  112.             {
  113.                ┬º┬ºenumerate(_loc2_.attributes);
  114.                var _loc0_ = null;
  115.                for(; (_loc0_ = ┬º┬ºenumeration()) != null; this.baseURLAttr.push(_loc2_.attributes[_loc6_]))
  116.                {
  117.                   var _loc6_ = ┬º┬ºenum_assign();
  118.                   if(_loc6_.toLowerCase() == "base")
  119.                   {
  120.                      continue;
  121.                   }
  122.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Attribute " + _loc6_ + " not supported in " + _loc2_.nodeName + " tag.");
  123.                }
  124.             }
  125.             else if(_loc2_.nodeName.toLowerCase() == "layout")
  126.             {
  127.                if(!_loc4_)
  128.                {
  129.                   this.parseLayout(_loc2_);
  130.                   _loc4_ = true;
  131.                }
  132.             }
  133.          }
  134.          _loc3_ = _loc3_ + 1;
  135.       }
  136.    }
  137.    function parseLayout(parentNode)
  138.    {
  139.       var _loc3_ = 0;
  140.       for(; _loc3_ < parentNode.childNodes.length; _loc3_ = _loc3_ + 1)
  141.       {
  142.          var _loc2_ = parentNode.childNodes[_loc3_];
  143.          if(_loc2_.nodeType != mx.video.SMILManager.ELEMENT_NODE)
  144.          {
  145.             continue;
  146.          }
  147.          if(_loc2_.nodeName.toLowerCase() != "root-layout")
  148.          {
  149.             continue;
  150.          }
  151.          for(var _loc5_ in _loc2_.attributes)
  152.          {
  153.             if(_loc5_.toLowerCase() == "width")
  154.             {
  155.                this.width = Number(_loc2_.attributes[_loc5_]);
  156.             }
  157.             else if(_loc5_.toLowerCase() == "height")
  158.             {
  159.                this.height = Number(_loc2_.attributes[_loc5_]);
  160.             }
  161.          }
  162.          if(!(isNaN(this.width) || this.width < 0 || isNaN(this.height) || this.height < 0))
  163.          {
  164.             this.width = Math.round(this.width);
  165.             this.height = Math.round(this.height);
  166.             return undefined;
  167.          }
  168.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag " + _loc2_.nodeName + " requires attributes id, width and height.  Width and height must be numbers greater than or equal to 0.");
  169.       }
  170.    }
  171.    function parseBody(parentNode)
  172.    {
  173.       var _loc6_ = 0;
  174.       var _loc3_ = 0;
  175.       for(; _loc3_ < parentNode.childNodes.length; _loc3_ = _loc3_ + 1)
  176.       {
  177.          var _loc2_ = parentNode.childNodes[_loc3_];
  178.          if(_loc2_.nodeType != mx.video.SMILManager.ELEMENT_NODE)
  179.          {
  180.             continue;
  181.          }
  182.          if((_loc6_ = _loc6_ + 1) <= 1)
  183.          {
  184.             if(_loc2_.nodeName.toLowerCase() == "switch")
  185.             {
  186.                this.parseSwitch(_loc2_);
  187.             }
  188.             else if(_loc2_.nodeName.toLowerCase() == "video" || _loc2_.nodeName.toLowerCase() == "ref")
  189.             {
  190.                var _loc5_ = this.parseVideo(_loc2_);
  191.                this.videoTags.push(_loc5_);
  192.             }
  193.             continue;
  194.          }
  195.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag " + parentNode.nodeName + " is required to contain exactly one tag.");
  196.       }
  197.       if(this.videoTags.length < 1)
  198.       {
  199.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" At least one video of ref tag is required.");
  200.       }
  201.    }
  202.    function parseSwitch(parentNode)
  203.    {
  204.       var _loc4_ = 0;
  205.       while(_loc4_ < parentNode.childNodes.length)
  206.       {
  207.          var _loc5_ = parentNode.childNodes[_loc4_];
  208.          if(_loc5_.nodeType == mx.video.SMILManager.ELEMENT_NODE)
  209.          {
  210.             if(_loc5_.nodeName.toLowerCase() == "video" || _loc5_.nodeName.toLowerCase() == "ref")
  211.             {
  212.                var _loc3_ = this.parseVideo(_loc5_);
  213.                if(_loc3_.bitrate == undefined)
  214.                {
  215.                   this.videoTags.push(_loc3_);
  216.                }
  217.                else
  218.                {
  219.                   var _loc6_ = false;
  220.                   var _loc2_ = 0;
  221.                   while(_loc2_ < this.videoTags.length)
  222.                   {
  223.                      if(this.videoTags[_loc2_].bitrate == undefined || _loc3_.bitrate < this.videoTags[_loc4_].bitrate)
  224.                      {
  225.                         _loc6_ = true;
  226.                         this.videoTags.splice(_loc2_,0,this.videoTags);
  227.                         break;
  228.                      }
  229.                      _loc2_ = _loc2_ + 1;
  230.                   }
  231.                   if(!_loc6_)
  232.                   {
  233.                      this.videoTags.push(_loc3_);
  234.                   }
  235.                }
  236.             }
  237.          }
  238.          _loc4_ = _loc4_ + 1;
  239.       }
  240.    }
  241.    function parseVideo(node)
  242.    {
  243.       var _loc3_ = new Object();
  244.       for(var _loc4_ in node.attributes)
  245.       {
  246.          if(_loc4_.toLowerCase() == "src")
  247.          {
  248.             _loc3_.src = node.attributes[_loc4_];
  249.          }
  250.          else if(_loc4_.toLowerCase() == "system-bitrate")
  251.          {
  252.             _loc3_.bitrate = Number(node.attributes[_loc4_]);
  253.          }
  254.          else if(_loc4_.toLowerCase() == "dur")
  255.          {
  256.             _loc3_.dur = this.parseTime(node.attributes[_loc4_]);
  257.          }
  258.       }
  259.       if(_loc3_.src == undefined)
  260.       {
  261.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Attribute src is required in " + node.nodeName + " tag.");
  262.       }
  263.       else
  264.       {
  265.          return _loc3_;
  266.       }
  267.    }
  268.    function parseTime(timeStr)
  269.    {
  270.       var _loc4_ = 0;
  271.       var _loc3_ = timeStr.split(":");
  272.       if(_loc3_.length < 1 || _loc3_.length > 3)
  273.       {
  274.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Invalid dur value: " + timeStr);
  275.       }
  276.       else
  277.       {
  278.          var _loc1_ = 0;
  279.          for(; _loc1_ < _loc3_.length; _loc4_ *= 60,_loc4_ += _loc2_,_loc1_ = _loc1_ + 1)
  280.          {
  281.             var _loc2_ = Number(_loc3_[_loc1_]);
  282.             if(!isNaN(_loc2_))
  283.             {
  284.                continue;
  285.             }
  286.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Invalid dur value: " + timeStr);
  287.          }
  288.          return _loc4_;
  289.       }
  290.    }
  291. }
  292.